bitcoind: add chainwork and size_on_disk to blockchain responses#6
Open
echennells wants to merge 1 commit into
Open
bitcoind: add chainwork and size_on_disk to blockchain responses#6echennells wants to merge 1 commit into
echennells wants to merge 1 commit into
Conversation
da9fc51 to
b42753f
Compare
2229142 to
3c589f2
Compare
b42753f to
07b441c
Compare
3c589f2 to
60fed34
Compare
a0fa0aa to
78827ce
Compare
chainwork is required by typed clients (rust-bitcoincore-rpc, corepc) on getblockchaininfo and getblockheader; size_on_disk on getblockchaininfo. Derived from chain_state cumulative work and cached by block hash (immutable) to bound the per-call genesis-span cost.
07b441c to
7a2ec96
Compare
78827ce to
ee2e710
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
chainworkto getblockchaininfo, getblockheader, and getblock (verbose), andsize_on_diskto getblockchaininfo, for the new bitcoind JSON-RPC interface (libbitcoin#795). Stacked on the bool-verbosity PR.bitcoind always includes these fields and typed clients (rust-bitcoincore-rpc, corepc) declare them required, so omitting them is a hard deserialization failure, not missing data — ord's startup
get_blockchain_info()fails against bs and it can't connect at all, even though it never reads chainwork.to_chain_work()computes cumulative work viaquery.get_chain_state(...), encoded as bitcoind does (32-byte big-endian hex);size_on_diskreportsquery.archive_size().The store keeps only per-header bits, so chainwork is summed from genesis (~3.2s at the testnet3 tip). The second commit adds a single-entry cache — work per hash is immutable, so no invalidation — which brings repeated tip queries to ~15ms. The durable fix, persisting cumulative work per header, is a store-schema decision left out of this PR.
Note for review: libbitcoin#795 omits chainwork deliberately, pointing callers to getchainwork; this reinstates it because typed clients require it on these responses and never call getchainwork.
Testing. Unit tests pin known chainwork constants on the ten-block test store; verified live on testnet3 (genesis and tip exact). Full suite green.